<template>
	<view class="sign">
		<image src="../../static/sign_bg.png" alt="" mode="widthFix" class="bg-img"></image>
		<view class="sign-info">
			<view class="point">
				我的积分
				<text>{{signData.point}}</text>
			</view>
			
			<view class="sign-record">已连续签到<text>{{signData.days}}</text>天</view>
			
			<view class="sign-btn" @tap="sign()" :class="signData.sign_status == 1 ? 'no': ''">{{signData.sign_status == 1 ? '已签到': '签到'}}</view>
		</view>
	</view>
</template>

<script>
	import Request from '../../common/request.js';
	export default {
		data() {
			return {
				signData: {}
			};
		},
		onLoad() {
			this.checkSignStatus();
		},
		methods: {
			//检查签到状态及用户积分
			checkSignStatus: function() {
				
				var url =  'sign/signStatus';
				var that = this;
				Request.send({
					url: url,
					sCallback: function(res) {
						that.signData = res.data;
					}
				})
			},
			//签到
			sign: function() {
				if(this.signData.sign_status == 1) {
					Request.alert('今天已签到');return;
				}
				
				var url =  'sign/sign';
				var that = this;
				Request.send({
					url: url,
					sCallback: function(res) {
						that.signData.sign_status = 1;
						that.signData.point = res.data.point;
						that.signData.days = res.data.days;
					}
				})
			}
		}
	}
</script>

<style>
		.bg-img{
			position: absolute;
			top: 0;
			left: 0;
			z-index: -1;
			width: 750upx;
			height: 100%;
		}
		
		.sign-info{
			z-index: 1;
			background: rgba(0, 0, 0, 0);
			position: absolute;
			z-index: 99;
			padding-top: 50px;
			width: 100%;
		}
		
		.sign-info .point{
			width: 158px;
			height: 158px;
			margin: 0 auto;
			border: 8px solid #fff;
			background: #FFA800;
			display: flex;
			flex-direction: column;
			color: #fff;
			border-radius: 50%;
			justify-content: center;
			align-items: center;
			font-size: 19px;
		}
		
		.sign-info .point b{
			font-size: 40px;
			padding-top: 20px;
		}
		
		.sign-btn{
			background: #ff5500;
			color: #fff;
			height: 50px;
			line-height: 50px;
			border-radius: 25px;
			width: 90%;
			margin: 40px auto;
			text-align: center;
		}
		
		.sign-btn.no{
			background: #999;
		}
		
		.sign-record{
			margin-top: 80px;
			text-align: center;
			font-size: 14px;
			color: #999;
		}
		
		.sign-record b{
			font-size: 20px;
			color: #e60012;
			padding: 0 10px;
		}
</style>
